package testcasegenerator.clp.methodlevel;

import graph.mcg.CGNode;
import graph.mcg.ConstraintNode;

import java.util.ArrayList;
import java.util.List;

import testcasegenerator.pathenumerator.*;
import tools.Tools;

public class ConstraintPredicate {

	// field
	private String name;
	private int pathNo = 1; // Path Number
	private final String param1 = "[]"; // Arg
	private final String param2 = "Result"; // Result

	private List<String> attr_list = new ArrayList<String>();
	private List<String> param_list = new ArrayList<String>();

	private List<String> inv = new ArrayList<String>();
	private List<String> pre = new ArrayList<String>();
	private List<String> post = new ArrayList<String>();

	public ConstraintPredicate(List<String[]> attrlist, List<String[]> paralist, TestPath invariant, TestPath precondition, TestPath postcondition) {
		for (String[] attr : attrlist) {
			attr_list.add(Tools.firstToUpperCase(attr[0]));
		}

		for (String[] para : paralist) {
			param_list.add(Tools.firstToUpperCase(para[0]));
		}

		// Invariant
		if (invariant != null) {
			inv.add("% Invariant");
			for (CGNode node : invariant.getTestpath()) {
				if (node instanceof ConstraintNode) {
					inv.add(node.toString());
				}
			}
		}

		// Precondition
		if (precondition != null) {
			pre.add("% Precondition");
			for (CGNode node : precondition.getTestpath()) {
				if (node instanceof ConstraintNode) {
					pre.add(node.toString());
				}
			}
		}

		// Postcondition
		if (postcondition != null) {
			post.add("% Postcondition");
			for (CGNode node : postcondition.getTestpath()) {
				if (node instanceof ConstraintNode) {
					post.add(node.toString());
				}
			}
		}

	}

	// method
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getPathNo() {
		return pathNo;
	}

	public void setPathNo(int pathNo) {
		this.pathNo = pathNo;
	}

	public String getParam1() {
		return param1;
	}

	public String getParam2() {
		return param2;
	}

	/*
	 * public void addPostcondition(String post) { post.add(post); }
	 * 
	 * public void addLastPostcondition(String post) { if (post.size() > 2) {
	 * String data = String.format("%s %s", post.get(1), post); data =
	 * data.replace("#", ""); post.remove(1); post.add(data); } else {
	 * post.add(post); } }
	 */

	public List<String> getAttrvar_list() {
		return attr_list;
	}

	public List<String> getParam_list() {
		return param_list;
	}

	public List<String> getInv() {
		return inv;
	}

	public void setInv(List<String> inv) {
		this.inv = inv;
	}

	public List<String> getPre() {
		return pre;
	}

	public void setPre(List<String> pre) {
		this.pre = pre;
	}

	public List<String> getPost() {
		return post;
	}

	public void setPost(List<String> post) {
		this.post = post;
	}

	public String toString() {
		String code = "";

		return code;
	}
}
